package com.example.livereplay.common.controller;

import com.example.livereplay.common.model.enity.LiveStream;
import com.example.livereplay.common.model.request.CreateLiveStreamRequest;
import com.example.livereplay.common.service.LiveStreamService;
import com.wingice.common.web.ErrorCodeInfo;
import com.wingice.common.web.ResultBean;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/liveStream")
@Tag(name = "直播管理")
public class LiveStreamController {
    @Resource
    private LiveStreamService liveStreamService;

    @Operation(summary = "创建直播")
    @PostMapping("/createLiveStream")
    public ResultBean<LiveStream> createLiveStream(@RequestBody @Valid CreateLiveStreamRequest createLiveStreamRequest){
        return ResultBean.restResult(liveStreamService.createLiveStream(createLiveStreamRequest), ErrorCodeInfo.OK);
    }

    @Operation(summary = "根据场地查找直播")
    @PostMapping("/getLiveByPlaceId")
    public ResultBean<List<LiveStream>> getLiveStreamByPlaceId(@RequestBody @Valid String placeId){
        return ResultBean.restResult(liveStreamService.getLiveStreamsByPlaceId(placeId), ErrorCodeInfo.OK);
    }

    @Operation(summary = "开始直播")
    @PostMapping("/startLiveStream")
    public ResultBean<LiveStream> startLiveStream(@RequestBody @Valid String liveStreamId){
        return ResultBean.restResult(liveStreamService.startLiveStream(liveStreamId), ErrorCodeInfo.OK);
    }
}
